<?php
/**
 * DataAccessMemcache
 * 
 * Database connection class.  
 * 
 * @author Gabriel PREDA
 * @copyright  Copyright (c) 2008-2009 Acceleron Team
 * @version    $Id: DataAccessMemcache.php 25 2008-11-28 20:20:19Z gabriel.preda $
 */

class DataAccessMemcache extends Memcache {

private $Servers;
	
/**
 * Connect to server pool 
 */
public function __construct($Servers) {
	$this->Servers = $this->Rearange($Servers);
	$this->CreatePool();
}

/**
 * Rearange the servers from the ini file 
 *
 * @param array $Servers
 * @return array
 */
private function Rearange($Servers) {
	$NewServers = array();
	
	foreach ($Servers['Host'] as $k => $v)
	{
		$NewServers[] = array(
			'Host'		=> $v,
			'Port'		=> $Servers['Port'][$k],
			'Weight'	=> $Servers['Weight'][$k]
			);
	}
	return $NewServers;
}

/**
 * Add all servers from the config in the server pool
 *
 */
private function CreatePool()
{
	foreach ($this->Servers as $Server)
	{
		parent::addserver($Server['Host'], $Server['Port'], false, $Server['Weight']);		
	}
}

/**
 * Close the connection with the server
 */
function __destruct() {
	parent::close();
}

}
